<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>意见库</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Expires" CONTENT="0">
    <meta http-equiv="Cache-Control" content="no-siteapp,no-transform,no-store, no-cache, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <link rel="shortcut icon" href="../../../favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../../../static/css/font.css">
    <link rel="stylesheet" href="../../../static/css/weadmin.css">
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../../static/css/buildUnit/common.css">
    <style>

    </style>
</head>
<body>
<div class="content tabel-fold">
    <form class="layui-form searchForm" action="">
        查询:
        <div class="layui-input-inline">
            <select name="articleType" class="articleType">
                <option value="">条文性质</option>
                <option value="1010">一般规范标准</option>
                <option value="1020">强条</option>
                <option value="1030">其他</option>
            </select>
        </div>
        <div class="layui-input-inline">
            <input type="text" name="tiaowenNo" placeholder="条文编号" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text" name="adviseTxt" placeholder="意见内容" autocomplete="off" class="layui-input">
        </div>
        <button class="layui-btn" lay-submit lay-filter="formDemo">查询</button>
        <button type="button" class="layui-btn layui-btn-normal" lay-filter="addBtn" id="addBtn">添加</button>
    </form>
    <table id="dataList" lay-filter="dataList"></table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-sm" lay-event="change">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete">删除</a>
        <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="apply">引用</a>
        <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="circleApply">圈阅引用</a>
    </script>
</div>
<script>
    layui.use(['jquery','configureCom','configure','jsDictFile','matchDict','form','table','bluebird','sessionFun','suggest','suggestBase'], function () {
        var $ = layui.jquery;
        var configureCom = layui.configureCom;
        var configure = layui.configure;
        var jsDictFile = layui.jsDictFile;
        var matchDict = layui.matchDict;
        var form = layui.form;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        var suggest = layui.suggest;
        var suggestBase = layui.suggestBase;
        window.drawingType = configureCom.GetQueryString('drawingType');
        var colsW = (drawingType === 'pdf' ? 220 : 300);
        var cols = [[
            {field: 'articleType', title: '条文性质',templet: function (d) {
                    if(d.articleType == 1){
                        return '<p>' + matchDict.name(d.articleType, configure.ARTICLE_TYPE) + '</p><p>强条类型:' + matchDict.name(d.qiangtiaoType, configure.QIANGTIAO_CODE) + '</p>'
                    }else{
                        return '<p>' + matchDict.name(d.articleType, configure.ARTICLE_TYPE) + '</p>'

                    }
                }
            },
            {field: 'tiaowenNum', title: '条文编号'},
            {field: 'adviseTxt', title: '意见',templet: function (d) {
                    return '<p>' + d.adviseTxt+ '</p><p>添加时间'+ d.createTime+ '</p>';
                }
            },
            {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 320}
        ]];
        //渲染表格
        configureCom.tableRender(configure.EXPERT_SUGGEST_BASE_HTTP, {}, cols, 'dataList', 10, 'full-200');

        //添加意见
        $('#addBtn').click(function () {
            sessionFun.remove(configure.SESSION_SUGGEST_BASE_DATA);
            top.layer.open({
                type: 2,
                title: '添加意见',
                area: configureCom.Psize1,
                content: configure.EXPERT_ADD_SUGGEST_BASE_HTML,
                btnAlign: 'c',
                btn: ['保存'],
                yes: function (index, layero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                    iframeWin.getData().then(function (res) {
                        console.log(res.result)
                        configureCom.postDataAjax(configure.EXPERT_ADD_SUGGEST_BASE_HTTP,res.result).then(function (data) {
                            if (data.code == 0) {
                                top.layer.msg(configure.MSG_ADD);
                                configureCom.tableReload(true);
                                top.layer.close(index);
                            }
                        });
                    });
                }
            });
        });
        //头工具栏事件
        table.on('tool(dataList)', function (obj) {
            //存入意见对象
            var data = obj.data;
            //将意见库当前条目数据存入session中
            sessionFun.set(configure.SESSION_SUGGEST_BASE_DATA,data);
            //存入意见对象
            sessionFun.set(configure.SESSION_SUGGEST_DATA,data);
            if (obj.event === 'change') {//修改意见
                top.layer.open({
                    type: 2,
                    title: '修改意见',
                    area: configureCom.Psize1,
                    content: configure.EXPERT_ADD_SUGGEST_BASE_HTML + '?type=change',
                    btnAlign: 'c',
                    btn: ['保存'],
                    yes: function (index, layero) {
                        var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                        iframeWin.getData().then(function (res) {
                            var dataAll  = res.result
                            var suggestBaseData = sessionFun.get(configure.SESSION_SUGGEST_BASE_DATA);
                            dataAll.bankId = suggestBaseData.bankId
                            suggestBase.change(res.result).then(function () {
                                top.layer.msg('修改成功');
                                configureCom.tableReload(true);
                                top.layer.close(index);
                            });
                        });
                    }
                });
            } else if (obj.event === 'delete') { //删除意见
                top.layer.confirm('确认删除当前意见吗?', function (index) {
                    top.layer.close(index);
                    suggest.deleteSuggestBank(data).then(function (res) {
                        top.layer.msg('删除成功！');
                        var randomId = obj.data.randomId || '';//pdf圈阅意见Id
                        if(randomId){
                            window.parWin.deleteYj(randomId);
                        }
                        configureCom.tableReload(true);
                    });
                });
            } else if (obj.event === 'apply') {//引用意见
                top.layer.open({
                    type: 2,
                    title: '引用意见',
                    area: configureCom.Psize1,
                    content: configure.EXPERT_ADD_SUGGEST_HTML,
                    btnAlign: 'c',
                    btn: ['保存'],
                    yes: function (index, layero) {
                        var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                        iframeWin.getData().then(function (res) {
                            console.log(res.result)
                            suggest.add(res.result).then(function () {
                                top.layer.msg('引用成功');
                                top.layer.close(index);
                            });
                        });
                    }
                });
            } else if (obj.event === 'circleApply') {
                //圈阅引用
                window.parWin.circleApply();
            }
        });

        //监听搜索
        configureCom.tableSearch();
    });
</script>
<script src="../../../static/js/main.js"></script>
</body>
</html>